# coding:utf-8

import xlrd
class Question(object):
    def __init__(self,title,answer,jiexi,selector):
        self.title = title
        self.answer = answer
        self.jiexi = jiexi
        for k, w in selector.items():
            setattr(self, k, w)

# path = '../resources/1.xls'
def getItem(path):
    # 获取excel文件对象
    readbook = xlrd.open_workbook(path)
    # 获取sheet
    sheet = readbook.sheet_by_index(0)#索引的方式，从0开始
    # 获取整行或者整列的值
    danxuan = []
    duoxuan = []
    tiankong = []
    panduan = []
    for i in range(sheet.nrows):
        # 获取题型 i 为行
        tixing = sheet.cell(i, 1).value
        sheet.row_values(i)
        title = sheet.cell_value(i,2) # 题目
        answer = '( '+ sheet.cell_value(i,3)+' )' # 答案
        jiexi = sheet.cell_value(i,4) # 解析
        selector = {
            'A':sheet.cell_value(i,7),
            'B':sheet.cell_value(i,8),
            'C':sheet.cell_value(i,9),
            'D':sheet.cell_value(i,10),
        }
        question = Question(title,answer,jiexi,selector)
        if tixing == '单选题':
            danxuan.append(question)
        if tixing == '多选题':
            duoxuan.append(question)
        if tixing == '填空题':
            tiankong.append(question)
        if tixing == '判断题':
            panduan.append(question)
    return danxuan,duoxuan,tiankong,panduan
    print(panduan[0].title)